import java.util.Scanner;
import java.util.*;

public class MC0413移动数组 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        // code here
        int n = input.nextInt();
        int q = input.nextInt();
        // 使用 Deque 来存储数组 a 的元素，方便两端操作
        Deque<Integer> deque = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            deque.addLast(input.nextInt());
        }
        // 读取 q 个操作
        int[] bq = new int[q];
        for (int i = 0; i < q; i++) {
            bq[i] = input.nextInt();
        }
        //执行q次操作
        for (int i = 0; i < q; i++) {
            int type = bq[i];
            if (type == 1) {
                // 将序列 a 的开头元素移至最后
                Integer firstElement  = deque.removeFirst();// 移除并获取头部元素
                deque.addLast(firstElement);// 将该元素添加到尾部
            } else if (type == 2) {
                // 将序列 a 的结尾元素移至开头
                int lastElement = deque.removeLast();   // 移除并获取尾部元素
                deque.addFirst(lastElement);          // 将该元素添加到头部
            }
        }
        // 输出最终的序列
        StringBuilder sb = new StringBuilder();
        for (Integer var : deque) {
            sb.append(var).append(" ");
        }
        System.out.println(sb.toString());
        input.close();
/*
        //使用链表
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();
        LinkedList<Integer> a = new LinkedList<>();
        for(int i=0;i<n;i++){
            a.add(input.nextInt());
        }
        int[] bq = new int[q];
        for (int i = 0; i < q; i++) {
            bq[i] = input.nextInt();
            if (bq[i]==1){
                Integer first = a.removeFirst();
                a.addLast(first);
            }else if(bq[i]==2){
                Integer last = a.removeLast();
                a.addFirst(last);
            }
        }
        StringJoiner sj = new StringJoiner(" "); // Java 8+
        for (Integer var : a) {
            sj.add(String.valueOf(var));
        }
        System.out.println(sj.toString());
        input.close();*/
    }
}
